package com.sun.personal.juc;

import java.util.concurrent.CountDownLatch;

/**
 * @author syh
 * @date 2021/7/6 13:39
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "\t离开教室");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        countDownLatch.await(); //CountDownLatch计数为0时，主线程才会被唤醒
        System.out.println(Thread.currentThread().getName() + "\t班长关闭教室");
    }
}

